package com.eastfair.saga.proxy.impl;

import com.eastfair.core.context.ContextUtil;
import com.eastfair.saga.proxy.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
@Slf4j
public class ProductServiceImpl implements ProductService {
    /**
     * 库存10个
     */
    public static Integer num =10000;
    @Override
    public Boolean reduceStock(Long productId, Integer count) throws Exception {
        num = num -count;
        log.info(ContextUtil.getProjectId()+" :::开始减扣库存：：" + count+",库存数量："+ num);
        int i=1/0;
        return true;
    }

    @Override
    public Boolean compensateStock(Long productId, Integer count) throws Exception {
        num = num + count;
        log.info(ContextUtil.getProjectId()+" :::开始减扣库存：：" + count+",库存数量："+ num);
        int i=1/0;
        return true;
    }

    @Override
    public Integer getPrice(Long productId) {
        return 100;
    }
}
